package com.niit.web.controller;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.niit.bean.NoteRepo;
import com.niit.service.NoteRepoService;
import com.niit.service.impl.NoteRepoServiceImpl;
import com.niit.utils.WebKit;

@WebServlet("/AddNoteRepoController")
public class AddNoteRepoController extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		NoteRepo repo = WebKit.request2Bean(request, NoteRepo.class);		
		NoteRepoService cs = new NoteRepoServiceImpl();
		OutputStream out = response.getOutputStream();
		if(cs.isNoteRepoExist(repo.getRepoName())){
			out.write("笔记本已经存在，请重命名!".getBytes());
		}else{
			int a = cs.add(repo);
			if(a>0){
				out.write("笔记本添加成功".getBytes());
			}else{
				out.write("笔记本添加失败".getBytes());
			}
		}
	}

}
